package com.morphiastic.utils;

import java.lang.reflect.Field;

public class ReflectionTools {

	
	/**
	 * 
	 * @param filedName
	 * @return
	 * @throws NoSuchFieldException 
	 */
	public static Field getDeclaredFieldFromHierarchy(Class clazz, String fieldName) throws NoSuchFieldException{
		try {
	      return clazz.getDeclaredField(fieldName);
	    } catch (NoSuchFieldException e) {
	      Class superClass = clazz.getSuperclass();
	      if (superClass == null) {
	        throw new NoSuchFieldException("Field " + fieldName + " cannot be found cause " + e);
	      } else {
	        return getDeclaredFieldFromHierarchy(superClass, fieldName);
	      }
	    }
	}
	
	 
}
